package com.javawork.igossip;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.javawork.igossip.model.Gossip;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.TouchDelegate;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

public class TabNewsFeedActivity extends ListActivity {

	ListView container;
	ArrayList<Gossip> gossips;
	TextView text_topbar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news_feed_tab);
		text_topbar = (TextView) getParent()
				.findViewById(R.id.text_main_topbar);
		text_topbar.setText(R.string.title_activity_news_feed_tab);
		container = getListView();
		gossips = GossipManager.getAllGossip();
		ArrayList<HashMap<String, Object>> showdata = new ArrayList<HashMap<String, Object>>();
		for (Gossip g : gossips) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("content", String.format("%s: %s (by %s)", g.target,
					g.content, g.source));
			map.put("picture",
					getResources().getDrawable(R.drawable.avatar_dummy));
			showdata.add(map);
			showdata.add(map);
		}
		setListAdapter(new MultiColorRowAdapter(this, showdata,
				R.layout.gossip_item, new String[] { "content", "picture" },
				new int[] { R.id.text_gossip_item, R.id.image_gossip_item },
				new int[] { Color.WHITE, Color.rgb(220, 220, 255) }));
		container.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Gossip.publicGossip = gossips.get(arg2);
				Intent intent = new Intent(TabNewsFeedActivity.this,
						GossipDetailActivity.class);
				startActivity(intent);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.news_feed_tab, menu);
		return true;
	}

}
